home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-07-10 | 2.4 KB | 102 lines | [TEXT/PJMM] |
- (* File PascalDemoBTMP.p *)
- (* A short example of how to use the 'BTMP' data structure *)
- (* in a Pascal program. *)
-
- program PascalDemoBTMP;
-
- type
- BitMapPtr = ^BitMap;
-
- BTMP = record
- baseAddr: Ptr;
- rowBytes: integer;
- bounds: Rect;
- bitImage: array[0..0] of integer;
- end;
- BTMPPtr = ^BTMP;
- BTMPHndl = ^BTMPPtr;
-
- const
- DFLT_BTMP_HEIGHT = 10;
- DFLT_BTMP_WIDTH = 20;
- DFLT_ROWBYTES = ((((DFLT_BTMP_WIDTH - 1) div 16) + 1) * 2);
- DFLT_BTMP_SIZE = (DFLT_BTMP_HEIGHT * DFLT_ROWBYTES);
- kLockStateFlag = $80;
-
- var
- theRect: Rect;
- theBitMapHndl: BTMPHndl;
-
- (************************************************************)
-
- function GetABTMP: BTMPHndl;
- (* create a sample BTMP resource and fill it with a striped pattern *)
- var
- h: BTMPHndl;
- p: BTMPPtr;
- bitsPtr: ^integer;
- i, nWords: integer;
- begin
- h := BTMPHndl(NewHandle(sizeof(BTMP) - sizeof(integer) + DFLT_BTMP_SIZE));
- p := h^;
- p^.baseAddr := nil;
- p^.rowbytes := DFLT_ROWBYTES;
- SetRect(p^.bounds, 0, 0, DFLT_BTMP_WIDTH, DFLT_BTMP_HEIGHT);
- bitsPtr := @p^.bitImage;
- nWords := DFLT_BTMP_SIZE div 2;
- for i := 1 to nWords do
- begin
- bitsPtr^ := 2816; (* striped pattern *)
- bitsPtr := Pointer(longint(bitsPtr) + sizeof(integer));
- end;
- GetABTMP := h;
- end;
-
- (************************************************************)
-
- procedure PlotPBitMap (r: Rect; p: BTMPPtr; mode: integer);
- var
- port: GrafPtr;
- begin
- GetPort(port);
- CopyBits(BitMapPtr(p)^, port^.portBits, p^.bounds, r, mode, nil);
- end;
-
- (************************************************************)
-
- function LockBitMap (h: BTMPHndl): SignedByte;
- var
- origState: SignedByte;
- theBitMapPtr: BTMPPtr;
- begin
- origState := HGetState(Handle(h));
- if (not Boolean(BitAnd(LONGINT(origState), kLockStateFlag))) then
- begin
- MoveHHi(Handle(h));
- HLock(Handle(h));
- end;
- theBitMapPtr := h^;
- theBitMapPtr^.baseAddr := @theBitMapPtr^.bitImage;
- LockBitMap := origState;
- end;
-
- (************************************************************)
-
- procedure PlotBitMap (r: Rect; h: BTMPHndl; mode: integer);
- (* analogous to PlotIcon *)
- var
- origState: SignedByte;
- begin
- origState := LockBitMap(h);
- PlotPBitMap(r, h^, mode);
- h^^.baseAddr := nil;
- HSetState(Handle(h), origState);
- end;
-
- (************************************************************)
-
- begin
- SetRect(theRect, 0, 0, DFLT_BTMP_WIDTH, DFLT_BTMP_HEIGHT);
- theBitMapHndl := GetABTMP;
- PlotBitMap(theRect, theBitMapHndl, srcCopy);
- end.